package com.deco.back.controller.content;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.deco.domain.vo.sys.CmsAdvTypeVo;
import com.deco.domain.vo.sys.CmsAdvVo;
import com.deco.service.sys.CmsAdvService;
import com.deco.service.sys.CmsAdvTypeService;
import com.free.common.vo.PageResponseVo;
import com.free.common.vo.PageSearchVo;
import com.free.common.vo.ResultModel;
import com.free.ext.web.spring.annoation.PageSearch;

/**
 * 广告管理 Controller
 * @author lengy
 *
 */
@Controller
public class CmsAdvController {
    @Autowired
    private CmsAdvService cmsAdvService;
    
    @Autowired
    private CmsAdvTypeService cmsAdvTypeService;


    @RequestMapping(value = "/cms_adv_list.do")
    public ModelAndView listPage(){
        ModelAndView mv = new ModelAndView("content/cmsadvlist");
        List<CmsAdvTypeVo> typeList = cmsAdvTypeService.getAll();
        mv.addObject("typeList", typeList);
        return mv;
    }

    @RequestMapping(value= "/cms_adv_list_page.do")
    @ResponseBody
    public PageResponseVo<CmsAdvVo> getList(@PageSearch PageSearchVo<CmsAdvVo> condition){
    	
        return cmsAdvService.pageInfo(condition);
    }

    @RequestMapping(value = "/cms_adv_edit.do")
    public ModelAndView editFixType(Integer id){
    	CmsAdvVo vo = null;
        ModelAndView mv = new ModelAndView("content/cmsadvedit");
        if(id != null){
            vo = cmsAdvService.getCmsAdv(id);
            mv.addObject("actNm","更新");
        }else{
            vo = new CmsAdvVo();
            vo.setId(0);
            mv.addObject("actNm","新增");
        }
        List<CmsAdvTypeVo> typeList = cmsAdvTypeService.getAll();
        mv.addObject("typeList", typeList);
        mv.addObject("obj",vo);
        return mv;
    }

    @RequestMapping(value ="/cms_adv_del.do")
    @ResponseBody
    public ResultModel batchDelete(@RequestParam(value = "ids[]")Integer[] ids){
        return cmsAdvService.batchDelete(ids);
    }

    @RequestMapping(value ="/cms_adv_edit_submit.do")
    @ResponseBody
    public ResultModel udpate(CmsAdvVo vo){
        return cmsAdvService.save(vo);
    }

    @RequestMapping(value ="/cms_adv_status.do")
    @ResponseBody
    public ResultModel updateStatus(CmsAdvVo vo){
        return cmsAdvService.save(vo);
    }
}
